struct INPUT
{
	float4 inPosition : SV_POSITION;
	float4 inColor : COLOR;
	float3 transformedNormal : NORMAL;
	float4 surfacePos : SURFACE;
	float3 uv : UV;
};

cbuffer DirectionalLight : register(b0)
{
	float4 dlightDir;
	float4 dlightColor;
};
cbuffer PointLight : register(b1)
{
	float4 plPos;
	float4 plightColor;
};
cbuffer SpotLight : register(b2)
{
	float4 slPos;
	float4 slightColor;
	float4 coneDir;

};
Texture2D texture1;
SamplerState Sampler;

float4 main( INPUT input ) : SV_TARGET
{
	

	float3 lightDir = -normalize((float3(dlightDir.xyz)));

	float3 wnrm = normalize(input.transformedNormal);
	float4 color = texture1.Sample(Sampler, float2(input.uv.xy));

	float4 colorAmb = saturate(color * float4(0.5f, 0.5f, 0.5f, 1.0f));
	
	float4 colorlight1 = saturate((dot(lightDir, wnrm)) * (colorAmb * dlightColor));


	float3 lightDir2 = normalize(float3(plPos.xyz) - float3(input.surfacePos.xyz));
	float lightRatio = clamp((dot(lightDir2, wnrm)), 0.0f, 1.0f);
	

	float4 colorlight2 = saturate(lightRatio * plightColor * color);

	float3 lightDir3 = normalize(float3(slPos.xyz) - float3(input.surfacePos.xyz));
	float surfaceR = clamp(dot(-lightDir3, coneDir), 0.0f, 1.0f);
	float spotFactor = (surfaceR > 0.9f) ? 1.0f : 0.0f;
	float lightRatio2 = clamp(dot(lightDir3, wnrm), 0.0f, 1.0f);

	float4 colorlight3 = saturate(spotFactor * lightRatio2 * slightColor * color);






		return  saturate(colorlight1 + colorlight2 + colorlight3);
	//return colorlight1;
}